<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('model_aggregations', function (Blueprint $table) {
            $table->id();

            $table->string('model')->default('')->comment('表');

            $table->string('aggregation_fun')->default('')->comment('函数');

            $table->string('field')->default('')->comment('字段');

            $table->bigInteger('value_int')->default(0)->comment('属性值，int类型');

            $table->string('value_string')->default('')->comment('属性值，string类型');

            $table->timestamps();

            $table->unique(['model', 'aggregation_fun', 'field',]);

            $table->comment('model聚合函数表');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('model_aggregations');
    }
};
